package com.star.spring.my.service.controller;

import com.star.spring.my.service.model.SensorData;
import com.star.spring.my.service.service.RuleEngineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sensor")
public class SensorController {
    @Autowired
    private RuleEngineService ruleEngineService;

    @Autowired
    public SensorController(RuleEngineService ruleEngineService) {
        this.ruleEngineService = ruleEngineService;
    }

    @PostMapping("/data")
    public void processSensorData(@RequestBody SensorData sensorData) {
        // Process and store sensor data
        // ...

        // Apply rules to check for alarms
        ruleEngineService.applyRules(sensorData);
    }
}
